#include <iostream>
int main()
{
    using namespace std;
    char ch;
    int count = 0; // use basic input

    // 1.using cin >> ch
    cout << "Enter characters; enter # to quit:\n";
    cin >> ch;        // get a character
    while (ch != '#') // test the character
    {
        cout << ch; // echo the character
        ++count;    // count the character
        cin >> ch;  // get the next character
    }
    cout << endl
         << count << " characters read\n";
    // get rid of rest of line
    // while (cin.get() != '\n')
    // ;
    // cin.get();

    /////////////////////////////////////////////////////////////////////////
    // 2. using cin.get();
    // get(char_type & __c) 这个是函数的声明,其中存在一个 & 解引用
    cout
        << "Enter characters; enter # to quit:\n";
    cin.get(ch); // use the cin.get(ch) function
    while (ch != '#')
    {
        cout << ch;
        ++count;
        cin.get(ch); // use it again
    }
    cout << endl
         << count << " characters read\n";
    // get rid of rest of line
    // while (cin.get() != '\n')
    //    ;
    // cin.get();

    /////////////////////////////////////////////////////////////////////////
    // 3.using EOF
    int ich; // for compatibility with EOF character
    ich = cin.get();
    while (!cin.eof()) // or cin.fail()
    {
        cout.put(char(ich));
        ++count;
        ich = cin.get();
    }
    cout << endl
         << count << " characters read\n";
    // get rid of rest of line
    // while (cin.get() != '\n')
    //    ;
    // cin.get();

    return 0;
}